//index.js
const jiaoyi= require('../../config').jiaoyi;
const getCurrentPagesApi = require('../../utils/common').getCurrentPagesApi;
//获取应用实例
const app = getApp()

Page({
  data: {
    content:[],
    navs:[{img: "../../images/p1_3.png",name: "市场d况"},
          {img: "../../images/p1_4.png",name: "海关数据"},
          {img: "../../images/p1_5.png",name: "订购数据"},
          {img: "../../images/p1_6.png",name: "定制数据"},
          {img: "../../images/p1_7.png",name: "新闻资讯"},
          {img: "../../images/p1_8.png",name: "木材交易"},
          {img: "../../images/p1_9.png",name: "English"},
          {img: "../../images/p2_1.png",name: "Русский"}]

  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  jiaoyi_detail: function(e) {
    // console.log(e);
    wx.navigateTo({
      url: `./jiaoyi_detail?id=${e.currentTarget.dataset.id}`
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'menu') {
      return {
        title: '国数源',
        path: getCurrentPagesApi()
      }
    }
    
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      // alert('d');
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
      this.ready();
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      // alert('a');
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
      this.ready();
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
          // alert('s');
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
          
        }
      })
      this.ready();
    }
  },
  ready: function() {
    var that = this
    wx.request({
      url: jiaoyi,
      success: function(res){
        console.log(res.data)
        that.setData({
          content: res.data
        })
      },
      fail: function(data){
        console.log(data)
      }
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
